package service

import (
	"github.com/gorilla/websocket"
	"html3/internal/container"
	"log"
)

// 绑定单个
func Bind(sc *container.ServiceContainer) error {
	if err := sc.UserClient.Set(sc.Conn, sc.ClientId, sc.UserId); err != nil {
		return err
	}
	return nil
}
func DeleteWs(sc *container.ServiceContainer) error {
	if err := sc.UserClient.Del(sc.ClientId); err != nil {
		return err
	}
	return nil
}

func SendMessageToClients(sc *container.ServiceContainer) error {
	client2, err := sc.UserClient.Get(sc.UserId)
	if err != nil {
		return err
	}
	err = client2.WriteMessage(websocket.TextMessage, []byte(sc.Message))
	if err != nil {
		log.Println("write:", err)
		return err
	}
	return nil
}
